package com.wc.acwing.思维.面包店;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/15 7:52
 * @description
 * https://www.acwing.com/problem/content/description/4908/
 */
public class Main {
    /**
     * 思路：
     * 二分 + 不等式求交集
     * 假设 是 tc - x, tm - y
     * x + y = mid -> y = mid - x
     * 0 <= x <= tc - 1, 0 <= y <= tm - 1, => max(0, mid + 1 - tm) <= x <= min(mid, tc - 1)
     *
     * a[i] * (tc - x) + b[i] * (tm - y) <= c[i] =>
     * (b[i] - a[i]) * x <= c[i] - a[i] * tc - bi * tm + b[i] * mid
     *
     * 0 <= mid <= tc + tm - 2;
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110;
    static long[] a = new long[N], b = new long[N], c = new long[N];
    static long n, tc, tm;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            tc = sc.nextLong();
            tm = sc.nextLong();
            for (int i = 1; i <= n; i++) {
                a[i] = sc.nextLong();
                b[i] = sc.nextLong();
                c[i] = sc.nextLong();
            }
            long l = 0, r = tc + tm - 2;
            while (l < r) {
                long mid = l + r >> 1;
                if (check(mid)) r = mid;
                else l = mid + 1;
            }
            out.println(r);
        }
        out.flush();
    }


    static boolean check(long mid) {
        long minv = Math.max(0, mid + 1 - tm), maxv = Math.min(mid, tc - 1);
        for (int i = 1; i <= n; i++) {
            double L = b[i] - a[i];
            double R = c[i] - (double) a[i] * tc - (double) b[i] * tm + (double) b[i] * mid;
            if (L == 0 && R < 0) return false;
            else if (L > 0) maxv = Math.min(maxv, (long) Math.floor(R / L));
            else if (L < 0) minv = Math.max(minv, (long) Math.ceil(R / L));
        }

        return minv <= maxv;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

